# !/usr/bin/env python
# -*- coding: utf-8 -*-

from concurrent import futures
import grpc
import grpc_server.distinguish_pb2 as distinguish_pb2, grpc_server.distinguish_pb2_grpc as distinguish_pb2_grpc
import data1.config
import os

_HOST = 'localhost'
_PORT = os.getenv('DISTINGUISH_SERVER_PORT', default='8080')


def distinguish(stub):
    with open(os.path.join(data1.config.yzm_path, '0001.' + data1.config.suffix), 'rb') as f:
        image = distinguish_pb2.Image(category=distinguish_pb2.Image.DATA1, data=f.read())
        response = stub.Distinguish(image)
        return response.yzm


def run():
    channel = grpc.insecure_channel(_HOST + ':' + _PORT)
    stub = distinguish_pb2_grpc.DistinguishStub(channel)
    print(distinguish(stub))


if __name__ == '__main__':
    run()
